#!/usr/bin/python (-)
# -*- coding: utf-8 -*-
#Create Time : 2006-7-26 上午09:03:39
#Create By User : oguard

from time import sleep
import subprocess
import sys
#===============================================================================
#import win32api
#import win32process
#import win32con
#===============================================================================

# arp table {ip address : mac address}
ARP_TAB = {'192.168.1.1':'00-0C-F1-B7-29-09', \
           '192.168.2.1':'00-0C-F1-B7-29-09', \
           '192.168.3.1':'00-0C-F1-B7-29-09'}

debugToggle = 0
def debug( *values ):
    if debugToggle == 0: return
    print >> sys.stderr, "DBG>", 
    for v in values: 
        print >> sys.stderr, v, 
        print >> sys.stderr, '.'

def build_cmd( i, m ):
    _c = "arp -s %s %s" % ( i, m )
    debug( 'cmd str = '+ _c )
    return _c

def running_arp( c ):
    try:
        returncode = subprocess.call( c, shell=True )
    except OSError: 
        return 65536
    return returncode
    
#===============================================================================
#def running_arp2( c ):
#        win32process.CreateProcessNone, c, None, None, 1, win32process.CREATE_NO_WINDOW|win32process.REALTIME_PRIORITY_CLASS, None, 'C:\\windows\\system32\\',win32process.STARTUPINFO())
#===============================================================================

def bind_arp():
    debug( 'start' )
    while 1:
        sleep( 8 )
        debug( 'OK' )
        for x, y in ARP_TAB.iteritems():
            _cmd_str = build_cmd( x, y )
            _rc = running_arp( _cmd_str )
            debug( 'rcode = '+ str( _rc ) )
            sleep( 2 )
    
if __name__ == "__main__":
    bind_arp()